<script>
	
	import {WxToken} from './common/util/weixin/wx_token.js'
	import {Api_url} from './common/config.js'
	var wxtoken = new WxToken();
	export default {
		onLaunch: function() {
			// #ifdef H5
			var ua = navigator.userAgent.toLowerCase();
			var isWeixin = ua.indexOf('micromessenger') != -1;
			if (!isWeixin) { 
				console.log("非公众号-暂不登陆")
			    return false;
			}
			wxtoken.verify('userinfo'); //静默获取openid	
			return
			//微信公众号获取token -必须是认证的服务号 
			let token =  uni.getStorageSync('token')
			if(!token){
				window.location.href = Api_url+'weixin/gzh_code'
			}
			// uni.request({
			// 	url:Api_url+'weixin/gzh_code',
			// 	method:'GET',
			// 	success: (res) => {
			// 		console.log(res)
			// 		// window.location.href = res.request_url;
			// 	}
			// })
			// #endif
			
			
			
			// #ifdef MP-WEIXIN
			uni.login({
				provider: 'weixin',
				success: function(loginRes) {
					let data = {
						'code': loginRes.code
					}
					user.get_xcx_token(data).then(res => {
						uni.setStorageSync('token', res.data.token)
						user.get_info().then(res=>{
							uni.setStorageSync('sfm',res.data.invite_code)
						})
					})
				}
			})
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
